import 'package:flutter/material.dart';

class OverlayWidget {
  late OverlayState _state;
  late OverlayEntry _entry;

  OverlayWidget({required BuildContext context, required Widget child}) {
    _entry = OverlayEntry(builder: (BuildContext ctx) {
      return child;
    });
    _state = Overlay.of(context) as OverlayState;
  }

  void insert() {
    _state.insert(_entry);
  }

  void remove() {
    try {
      _entry.remove();
    } catch (e) {}
  }
}
